import os
import sys

os.system("clear")
print "System software selection"

# Riempie la lista dei server, delle app e dei driver, sfogliando le 
#  cartelle
server_list = []
app_list = []
driver_list = []

# Servers
l = os.listdir("src/server")
for x in l:
	try:
		l2 = os.listdir("src/server/"+x)
		for y in l2:
			if y == x:
				server_list.append([x, "src/server/"+x+"/"+x])
	except:
		pass

# Driver
l = os.listdir("src/driver")
for x in l:
	try:
		l2 = os.listdir("src/driver/"+x)
		for y in l2:
			if y == x:
				driver_list.append([x, "src/driver/"+x+"/"+x])
	except:
		pass
		
		
# App
l = os.listdir("src/app")
for x in l:
	try:
		l2 = os.listdir("src/app/"+x)
		for y in l2:
			if y == x:
				app_list.append([x, "src/app/"+x+"/"+x])
	except:
		pass

#server_list = [["vfs", " "], ["network", " "], ["gui", " "]]
#driver_list = [["keyboard", " "], ["mouse", " "]]
koption_list = [["debug", "DEBUG", "bool"], ["arch", "ARCH", "str"]]



# Server iniziali e drivers
#print "servers to start immediatly after kernel:"
#for x in server_list:
#	print " " + str(server_list.index(x)) + "\t" + x[0]

#selections = raw_input("selection (separated by spaces): ")



# Server, app e driver da caricare
print "\n\nServers to add to live:"
for x in server_list:
	print " " + str(server_list.index(x)) + "\t" + x[0]

selections = raw_input("selection (separated by spaces): ")


print "\n\nDrivers to add to live:"
for x in driver_list:
	print " " + str(driver_list.index(x)) + "\t" + x[0]

selections = raw_input("selection (separated by spaces): ")


print "\n\nApps to add to live:"
for x in app_list:
	print " " + str(app_list.index(x)) + "\t" + x[0]

selections = raw_input("selection (separated by spaces): ")


print "\n\nOptions to set in kernel:"
for x in koption_list:
	a = raw_input("\t" + x[0] + ": ")

	if x[0] == "arch":
		f = open("src/arch.am", "w")
		f.write("ARCH = "+a);
		f.close()
